package com.zang.blogz.listener;

import com.zang.blogz.entity.ExceptionLog;
import com.zang.blogz.entity.OperationLog;
import com.zang.blogz.event.ExceptionLogEvent;
import com.zang.blogz.event.OptLogEvent;
import com.zang.blogz.service.ExceptionLogService;
import com.zang.blogz.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: ZVerify
 * @Description: 日志触发监听
 * @DateTime: 2022/9/3 18:06
 **/
@Component
public class OptLogEventListener {

    @Autowired
    private OperationLogService operationLogService;

    @Async
    @EventListener(OptLogEvent.class)
    public void saveExceptionLog(OptLogEvent optLogEvent) {

        operationLogService.save((OperationLog) optLogEvent.getSource());
    }
}
